#include <glib.h>

static void _byte_array_append(GByteArray *barr)
{
    gchar str0[8] = {0};
    gchar str1[8] = {0};
    gchar str2[8] = {0};
    gchar str3[8] = {0};

    g_strlcpy(str0, "Hello", 8);
    g_strlcpy(str1, ",", 8);
    g_strlcpy(str2, "World", 8);
    g_strlcpy(str3, "\0", 8);

    g_byte_array_append(barr, (guint8 *)str0, 5);
    g_byte_array_append(barr, (guint8 *)str1, 1);
    g_byte_array_append(barr, (guint8 *)str2, 5);
    g_byte_array_append(barr, (guint8 *)str3, 1);

    g_print("barr(in-func):(len:%d)%s \n", barr->len, barr->data);
}

gint main(gint argc, gchar **argv)
{
    GByteArray *barr = NULL;
    guint i = 0;

    barr = g_byte_array_new();

    _byte_array_append(barr);

    g_print("barr(out-func):(len:%d)%s \n", barr->len, barr->data);

    g_print("barr->data: \n");
    for(i=0; i<barr->len; i++) {
        g_print("%c ", barr->data[i]);
    }
    g_print("\n");

    g_byte_array_free(barr, TRUE);

    return 0;
}